/*
 *说明：资源账号信息表 增加/修改脚本
 *
 *@author liuxun 2012-03-18
*/

var opeForm;
var operationType;

$(function(){

	opeForm=$('#opeForm');
	operationType = $('#operationType').val();

	if (operationType == 0) {
		opeForm.url = 'C_RSC_ACC!doInsertPullRSCACC.do';

	} else if(operationType == 1){
		opeForm.url = 'C_RSC_ACC!doUpdate.do';

	} 
	$('#is_modify_password').change(changePassword);
	$('#okBtn').click(doOk);
	$('#cancelBtn').click(closeWin);
});

//选择资源
function select_c_rsc() {
	var node_id = $('#node_id').val();
	var action = "C_RSC!showSelect.do?model.node_id=" + node_id;
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#rsc_id').val(row.rsc_id);
		$('#rsc_name').val(row.rsc_name);
		$('#node_id').val(row.node_id);
	}
}

// 选中“修改密码”复习框，取消密码输入框禁用状态
function changePassword() {
	var isCheck = $('#is_modify_password').attr('checked');
	var showEditPass = $("#showEditPass").attr("checked");
	if (isCheck) {
		//$('#password').attr('disabled', false);
		if(showEditPass){
			document.getElementById('editPass').innerHTML='<input type="text" id="password" name="model.password" required="true" validType="" class="easyui-validatebox  editMainText" value="" maxlength="50">';
		}else{
			document.getElementById('editPass').innerHTML='<input type="password" id="password" name="model.password" required="true" validType="" class="easyui-validatebox  editMainText" value="" maxlength="50">';
		}
	} else if(!isCheck){
		$('#password').val('');
		 $("#showEditPass").attr("checked", false);
		$('#password').attr('disabled', true);
	}
	
}

//新增时用到
function passwordTypeChange(){
	var temp = document.getElementById('password').value;
	if($("#showPass").attr("checked")){
		document.getElementById('pass').innerHTML='<input type="text" id="password" name="model.password" required="true" validType="" class="easyui-validatebox  editMainText" value="${model.password}" maxlength="50">';
	}else{
		document.getElementById('pass').innerHTML='<input type=password id="password" name="model.password" required="true" validType="" class="easyui-validatebox  editMainText" value="${model.password}" maxlength="50">';
	} 
	document.getElementById('password').value=temp;
}

//修改时 逻辑判断是否明文显示密码框
function editPasswordTypeChange(){
	var temp = document.getElementById('password').value;
	var isCheck = $('#is_modify_password').attr('checked');
	var showEditPass = $("#showEditPass").attr("checked");
	
	if(showEditPass && isCheck){
		document.getElementById('editPass').innerHTML='<input type="text" id="password" name="model.password" required="true" validType="" class="easyui-validatebox  editMainText" value="${model.password}" maxlength="50">';
	}else if(!showEditPass && isCheck){
		document.getElementById('editPass').innerHTML='<input type=password id="password" name="model.password" required="true" validType="" class="easyui-validatebox  editMainText" value="${model.password}" maxlength="50">';
	} 
	document.getElementById('password').value=temp;
}

//保存按钮操作
function doOk() {
	var validateResult = opeForm.form('validate');

	if (!validateResult){
		showInfoWin('请正确填写信息!');
		return;
	}

	var isCheck = $('#is_modify_password').attr('checked');
	if (isCheck) {
		var password = $('#password').val();
		if (isEmpty(password)) {
			showInfoWin('你选择修改密码，请输入新密码!');
			return;
		}
	}
	
	showSystemProccessing();
	var options = { 
		url: opeForm.url,
		type: 'post',
		success: function(data){
			removeSystemProccessing();
			getOpenerWin().afterOK();
		    if (operationType == '0') {
				showInfoWin('操作成功!', refreshWin);

			} else {
				showInfoWin('操作成功!', function() {window.close();});
			}
		}
	};

	opeForm.ajaxSubmit(options);
}
